package deleteface.bank.jqsoft.cn.deleteface;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.widget.Toast;

import com.tencent.bugly.Bugly;

import org.litepal.LitePalApplication;

import java.util.ArrayList;
import java.util.List;

import deleteface.bank.jqsoft.cn.deleteface.base.AppComponent;
import deleteface.bank.jqsoft.cn.deleteface.base.AppModule;
import deleteface.bank.jqsoft.cn.deleteface.base.BphsConstants;
import deleteface.bank.jqsoft.cn.deleteface.base.DaggerAppComponent;
import deleteface.bank.jqsoft.cn.deleteface.setip.SettingServerAdapter;
import deleteface.bank.jqsoft.cn.deleteface.setip.SettingServerBean;

public class MyApplivation  extends Application {

    private static AppComponent appComponent;

    @Override
    public void onCreate() {
        super.onCreate();
        BphsConstants.appweburltype =getMetaDataFromManifest(getApplicationContext(), "AREA_NAME") ;
        Bugly.init(getApplicationContext(), "d245786e9c", false);
        LitePalApplication.initialize(this);
//        SettingServerBean bean=new SettingServerBean("218.22.110.114:8801","218.22.110.114:9099","固镇县","","1") ;

        SharedPreferences userSettings = getSharedPreferences("setting", 0);
        int  clearSaveState= userSettings.getInt("clearSaveState",0);
        if (clearSaveState==0){
//					file.delete();
            init();
            SharedPreferences.Editor editor = userSettings.edit();
            editor.putInt("clearSaveState",1);
            editor.apply();
        }


    }
    /**
     * 获取build中的参数值
     *
     * @param context 上下文
     * @param key     键
     * @return 返回值
     */
    public static int getMetaDataFromManifest(Context context, String key) {
        int result = 1;
        try {
            ApplicationInfo appInfo = context.getPackageManager()
                    .getApplicationInfo(context.getPackageName(),
                            PackageManager.GET_META_DATA);
            result = appInfo.metaData.getInt(key);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            result = 1;
        }
        return result;
    }

    public AppComponent getAppComponent() {
        if (appComponent == null) {
            this.setupApplicationComponent();
        }
        return appComponent;
    }
    // private String tag;
//    Dagger
    private void setupApplicationComponent() {
        appComponent = DaggerAppComponent.builder()
                .appModule(new AppModule(this))
                .build();
    }

    public static MyApplivation get(Context context) {
        return (MyApplivation) context.getApplicationContext();
    }


    private void init(){
        List<SettingServerBean> urlList = new ArrayList<>();
        urlList.add(new SettingServerBean("218.22.110.114:8801",
                "218.22.110.114:9099","固镇","","1"));
        urlList.add(new SettingServerBean("218.23.17.201:8801",
                "218.23.17.201:9099","临泉","","1"));
        urlList.add(new SettingServerBean("218.22.56.86:8801",
                "218.22.56.86:9099","肥东","218.22.56.86","0"));
        urlList.add(new SettingServerBean("60.171.220.164:8801"
                ,"60.171.220.164:9099","泗县","60.171.220.164","0"));
        urlList.add(new SettingServerBean("60.173.1.131:8802",
                "60.173.1.131:9088","铜陵郊区","60.173.1.131","0"));
        urlList.add(new SettingServerBean("117.57.168.206:8801",
                "117.57.168.206:9099","濉溪","117.57.168.206","0"));
        urlList.add(new SettingServerBean("112.30.211.80:8801",
                "112.30.211.227:9099","太湖","112.30.211.227","0"));
        urlList.add(new SettingServerBean("60.171.137.137:8801",
                "60.171.137.137:9099","岳西","60.171.137.137","0"));
        urlList.add(new SettingServerBean("60.173.152.105:8801",
                "60.173.152.105:9099","舒城","60.173.152.105","0"));
        urlList.add(new SettingServerBean("220.179.65.153:8801",
                "220.179.65.153:9099","颍上","220.179.65.153","0"));
        urlList.add(new SettingServerBean("220.179.84.235:8801",
                "220.179.84.235:9099","颍东","220.179.84.235","0"));
        urlList.add(new SettingServerBean("220.179.90.8:8801",
                "220.179.90.8:9099","太和","220.179.90.8","0"));
        urlList.add(new SettingServerBean("220.179.82.42:8801",
                "220.179.82.42:9099","颖泉","220.179.82.42","0"));
        urlList.add(new SettingServerBean("223.214.193.118:8801",
                "223.214.193.70:9098","广德","223.214.193.70","0"));
        urlList.add(new SettingServerBean("218.22.94.164:8801",
                "218.22.94.164:9099","怀远","218.22.94.164","0"));
        urlList.add(new SettingServerBean("220.180.153.108:8801",
                "220.180.153.108:9099","颍州","220.180.153.108","0"));
        urlList.add(new SettingServerBean("223.247.139.12:8801",
                "223.247.214.34:9099","潜山","223.247.139.12","0"));
        urlList.add(new SettingServerBean("60.173.182.237:8801",
                "60.173.182.237:9099","裕安区","60.173.182.237","0"));
        urlList.add(new SettingServerBean("60.169.64.111:8801",
                "60.169.64.111:9099","南陵县","60.169.64.111","0"));
        urlList.add(new SettingServerBean("60.173.1.131:8802/",
                "60.173.1.131:9088","铜陵郊区","60.173.1.131","0"));
        urlList.add(new SettingServerBean("192.168.45.241:8801",
                "192.168.45.241:9088","测试地址","192.168.45.241","0"));
        urlList.add(new SettingServerBean("223.247.177.163:8801",
                "223.247.177.163:9099","青阳","223.247.177.163","0"));
        urlList.add(new SettingServerBean("60.170.96.106:8801",
                "60.170.96.106:9098","五河","60.170.96.106","0"));
        urlList.add(new SettingServerBean("223.240.84.65:8801",
                "223.240.84.140:9099","石台县","223.240.84.65","0"));
        urlList.add(new SettingServerBean("218.23.112.74:8801",
                "218.23.112.74:9099","长丰县","218.23.112.74","0"));
        urlList.add(new SettingServerBean("60.171.140.109:8801",
                "60.171.140.109:9099","宿松县","60.171.140.109","0"));
        urlList.add(new SettingServerBean("223.243.29.75:8801",
                "223.243.29.66:9099","涡阳县","223.243.29.75","0"));
        urlList.add(new SettingServerBean("60.173.172.139:8801",
                "60.173.172.139:8088","霍邱县","60.173.172.139","0"));
        urlList.add(new SettingServerBean("60.173.147.11:8801",
                "60.173.147.11:9099","金安区","60.173.147.11","0"));
        urlList.add(new SettingServerBean("60.173.133.111:8801",
                "60.173.133.111:9099","寿县","60.173.133.111","0"));

        urlList.add(new SettingServerBean("60.171.146.122:8801",
                "60.171.146.122:9099","怀宁县","60.171.146.122","0"));
        urlList.add(new SettingServerBean("60.171.230.50:8801",
                "60.171.230.50:9098","灵璧县","60.171.230.50","0"));
        urlList.add(new SettingServerBean("218.23.80.99:8801",
                "218.23.80.99:9099","霍山县","218.23.80.99","0"));

        urlList.add(new SettingServerBean("112.30.147.26:8801",
                "112.30.147.26:8088","宜秀区","112.30.147.26","0"));

        urlList.add(new SettingServerBean("60.174.199.175:8801",
                "60.174.199.175:9099","巢湖市","60.174.199.175","0"));
        urlList.add(new SettingServerBean("112.27.11.208:8801",
                "112.27.11.208:9099","旌德县","112.27.11.208","0"));
        urlList.add(new SettingServerBean("60.173.110.110:8801",
                "60.173.110.110:9099","绩溪县","60.173.110.110","0"));
        urlList.add(new SettingServerBean("112.30.147.27:8801",
                "112.30.147.27:9099","安庆大观区","112.30.147.27","0"));

        urlList.add(new SettingServerBean("112.29.244.172:8801",
                "112.29.244.172:9099","明光市","112.29.244.172","0"));
        urlList.add(new SettingServerBean("60.170.61.234:8801",
                "60.170.61.234:9099","禹会区","60.170.61.234","0"));
        urlList.add(new SettingServerBean("223.241.102.206:8801",
                "223.241.102.206:9099","无为县","223.241.102.206","0"));
        urlList.add(new SettingServerBean("61.190.123.89:8801",
                "61.190.123.89:9099","淮上区","61.190.123.89","0"));
        urlList.add(new SettingServerBean("112.28.18.144:8801",
                "114.98.238.153:9099","泾县","112.28.18.144","0"));
        urlList.add(new SettingServerBean("114.98.232.150:8801",
                "223.247.193.12:9099","龙子湖","114.98.232.150","0"));
        urlList.add(new SettingServerBean("223.241.225.11:8801",
                "223.241.225.11:9099","含山","223.241.225.11","0"));
        urlList.add(new SettingServerBean("112.53.235.2:8801",
                "112.53.235.2:9099","来安","112.53.235.2","0"));
        urlList.add(new SettingServerBean("218.22.94.164:8802",
                "218.22.94.164:9100","蚌山","218.22.94.164","0"));
        urlList.add(new SettingServerBean("223.247.130.228:8801",
                "223.247.178.64:9099","芜湖县","223.247.178.64","0"));

        urlList.add(new SettingServerBean("223.244.226.109:8801",
                "223.244.226.109:9099","全椒县","223.244.226.109","0"));
        urlList.add(new SettingServerBean("117.66.188.141:8801",
                "117.66.188.179:9099","枞阳县","117.66.188.179","0"));
        urlList.add(new SettingServerBean("60.170.202.45:8801",
                "60.170.202.45:9099","蚌埠经开区","60.170.202.45","0"));
        urlList.add(new SettingServerBean("223.247.157.176:8801",
                "183.166.187.49:9099","祁门县","223.247.157.176","0"));
        urlList.add(new SettingServerBean("183.166.187.69:8801",
                "183.166.187.69:8087","黟县","183.166.187.69","0"));

        urlList.add(new SettingServerBean("60.174.134.162:8801",
                "60.174.134.170:9099","和县","60.174.134.162","0"));
        urlList.add(new SettingServerBean("112.30.147.29:8801",
                "112.30.147.29:9099","安庆经开区","112.30.147.29","0"));
        urlList.add(new SettingServerBean("112.30.147.29:8801",
                "61.167.145.208:9099","大庆市","61.167.145.208","0"));
        urlList.add(new SettingServerBean("60.168.132.92:7701",
                "60.168.132.92:9998","公司测试地址","60.168.132.92","0"));
        urlList.add(new SettingServerBean("112.30.147.28:8801",
                "112.30.147.28:9098","迎江区","112.30.147.28","0"));
        urlList.add(new SettingServerBean("60.168.132.92:7701",
                "192.168.45.240:9098","公司测试地址内网","192.168.45.240","0"));

        urlList.add(new SettingServerBean("218.22.110.114:8801",
                "10.1.74.60:8087","柯炎本机","192.168.45.240","0"));

        urlList.add(new SettingServerBean("114.215.197.163:8801",
                "223.247.178.64:9099","本溪","223.247.178.64","0"));
        urlList.add(new SettingServerBean("120.209.93.231:8801",
                "120.209.93.231:9099","烈山区","120.209.93.231","0"));

        for(int i=0;i<urlList.size();i++){
            urlList.get(i).save();
        }

    }
}
